package com.dormitory.service.impl;

import com.dormitory.dao.UserDao;
import com.dormitory.dao.impl.UserDaoImpl;
import com.dormitory.model.User;
import com.dormitory.service.UserService;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();

    @Override
    public boolean register(User user) {
        // 检查用户名是否已存在
        if (userDao.findByUsername(user.getUsername()) != null) {
            return false;
        }
        
        // 设置默认状态为启用
        user.setStatus("启用");
        return userDao.save(user);
    }

    @Override
    public User login(String username, String password) {
        User user = userDao.findByUsername(username);
        if (user != null && user.getPassword().equals(password) && "启用".equals(user.getStatus())) {
            return user;
        }
        return null;
    }
} 